package com.sgy.rmi.server;

import com.sgy.rmi.service.IUserService;
import com.sgy.rmi.service.impl.IUserServiceImpl;

import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

/**
 * 服务端
 */
public class RMIServer {

    public static void main(String[] args) {
        try {
            // 注册registry实例，绑定端口
            Registry registry = LocateRegistry.createRegistry(9998);
            // 创建远程对象
            IUserService iUserService = new IUserServiceImpl();
            // 将远程对象注册到RMI服务器上（服务端注册表）
            registry.rebind("userService", iUserService);
            System.out.println("RMI服务端启动成功...");
        } catch (RemoteException e) {
            e.printStackTrace();
        }

    }
}
